package exercise9;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Exercise16_07 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        TextField minute_tf=new TextField();
        TextField second_tf=new TextField();
        TextField hour_tf=new TextField();
        ClockPane clockPane=new ClockPane();

        hour_tf.setAlignment(Pos.BOTTOM_LEFT);
        minute_tf.setAlignment(Pos.BOTTOM_CENTER);
        second_tf.setAlignment(Pos.BOTTOM_RIGHT);


        //创建布局
        Pane pane_select=new HBox();
        Pane pane_text=new HBox();
        BorderPane pane=new BorderPane();

        //总布局
        pane.setCenter(clockPane);
        pane.setBottom(pane_select);

        //callback
        hour_tf.setOnAction(event -> {
            clockPane.setHour(Integer.parseInt(hour_tf.getText()));
        });
        minute_tf.setOnAction(event -> {
            clockPane.setMinute(Integer.parseInt(minute_tf.getText()));
        });
        second_tf.setOnAction(event -> {
            clockPane.setSecond(Integer.parseInt(second_tf.getText()));
        });

        //初始化界面
        pane_select.getChildren().addAll(new Label("小时"),hour_tf,new Label("   分钟"),
                minute_tf,new Label("   秒"),second_tf);
        primaryStage.setScene(new Scene(pane,800,400));
        primaryStage.setTitle("可调节的时钟");
        primaryStage.show();
    }
}
